package com.zzw.dao;

import com.zzw.model.Venue;
import com.zzw.model.VenueQuery;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface VenueDao {
    @Insert("INSERT INTO a_venue(name, img, province, city, country, address, lng, lat, brief, seq) " +
            "values (#{name}, #{img}, #{province}, #{city}, #{country}, #{address}, #{lng}, #{lat}, #{brief}, #{seq})")
    int insert(Venue venue);

    @Select("<script> select  *  from  a_venue" +
            " where 1 = 1 " +
            " <if test = 'id != null'> " +
            " and id = #{id} " +
            "</if>" +
            " <if test = 'name != null'> " +
            " and name like concat ('%',trim(#{name}),'%') " +
            "</if>" +
            " <if test = 'country != null'> " +
            " and country = #{country} " +
            "</if>" +
            "</script>")
    List<Venue> select(VenueQuery query);

    @Delete("DELETE FROM a_venue WHERE id=#{id}")
    int delete(Integer id);

    @Update("UPDATE a_venue SET name=#{name},img=#{img}, province=#{province}, city=#{city}, country=#{country}, " +
            "address=#{address}, lng=#{lng}, lat=#{lat}, brief=#{brief}, seq=#{seq} WHERE id=#{id}")
    int update(Venue venue);
}
